var zTreeObj;
var menus = $("#menus").val();
// zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）
var setting = {
		 data: {
		        keep: {
		            parent: false,
		            leaf: false
		        },
		        simpleData: {
		            enable: true
		        }
		    },
		callback: {
	        onClick: function(event,treeId,treeNode) {
	        	$("#testIframe").attr("src", JSSYSMANAGERV1 + treeNode.fileUrl);
	        }
	    }
};
// zTree 的数据属性，深入使用请参考 API 文档（zTreeNode 节点数据详解）
//;console.log(menus);
$(document).ready(function(){
   /* zTreeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
   $("#treeDemo_1_span").click();  
   demoIframe = $("#testIframe"); */
   
   var result = jQuery.parseJSON(menus);
   var zNodes = [];
   for (var i = 0; i < result.length; i++) {
       zNodes.push({
           id: result[i].id,
           pId: result[i].pId,
           name: result[i].name,
           fileUrl:result[i].fileUrl,
           menuType:result[i].menuType,
           hasChildren: result[i].hasChildren
       });
   }
   $.fn.zTree.init($("#treeDemo"), setting, zNodes);
	
   var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
   treeObj.expandAll(true);
   $("#treeDemo_1_span").click();
});

function reinitIframe(){//iframe自适应高度
	var iframe = document.getElementById("testIframe");
	try{
		var bHeight = iframe.contentWindow.document.body.scrollHeight;
		var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
		var height = Math.max(bHeight, dHeight);
		iframe.height = height;
	}catch (ex){}
}
window.setInterval("reinitIframe()", 200);